﻿<html>
	<head>
		<title>User edit</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="v-a.css" type="text/css">
	</head>
	<?php	
		error_reporting(E_ALL);
		ini_set('display_errors', '1');
		session_start();
		//print_r ($_POST);
		require_once ('dbConnect.php');
		include ('functions.php');
		if(isset($_POST['Vissza'])) {
			$_SESSION['uzenet']="";
			header('Location: '.$_SESSION['vissza']);
			exit;
		}
		if(isset($_POST['Frissit'])) {
			$result=MyDatabase::getConnection()->multi_query("CALL updateuser('".$_POST['usernameTB']."','".$_POST['telefonszamTB']."','".$_POST['usertipusCB']."','".$_POST['aktivCB']."','".$_POST['egyenlegTB']."')");
			
			if (!$result) {
				$_SESSION['uzenet']='mysql_error: ' . MyDatabase::getConnection()->error;
			}
			else{
				$_SESSION['uzenet']='Frissítve';
			}
		}
		if(isset($_SESSION['editeduser'])) {
			$row=useredit($_SESSION['editeduser']);
				$_POST['usernameTB']=$row[0];
				$_POST['telefonszamTB']=$row[1];
				$_POST['usertipusCB']=$row[2];
				$_POST['aktivCB']=$row[3];
				$_POST['egyenlegTB']=$row[4];
		}

			
		
		
	?>	
	<body>
		<table ><tr HEIGHT="10"><td WIDTH="80%">User edit</td><td WIDTH="20%"><?php include('kilepes.php');?></td></tr></table>
		
		<hr>
		
		<?php 
			if(isset($_POST['Frissit'])) {printf($_SESSION['uzenet']);}
		?>
		<hr>
		<form name='newuserForm' method='post' action="useredit.php">
		<table>
		<tr>
		<td>
		<input type='submit'  class='button' name='Vissza' value='<< vissza' />
		</td><td>
		<input type='submit'  class='button' name='Frissit' value='frissít' />
		</td>
		</tr>
		</table>
			<table width='400px'>
				<tr>
					<td>
						<label>felhasználó név:</label>
					</td>
					<td>
						<input  type='text' name='usernameTB' maxlength='20' size='20' value='<?php 
							if(isset($_POST['usernameTB']))
								print $_POST['usernameTB'];
						?>'>
					</td>
				</tr>
				<tr>
					<td>
						<label>felhasználó típus:</label>
					</td>
					<td>
						<select name='usertipusCB'>
							<option value="admin" <?php if($_POST['usertipusCB']=='admin'){print "selected='selected' ";}?>>admin</option>
							<option value="termelő" <?php if($_POST['usertipusCB']=='termelő'){print "selected='selected' ";}?>>termelő</option>
							<option value="vásárló" <?php if($_POST['usertipusCB']=='vásárló'){print "selected='selected' ";}?>>vásárló</option>
						</select>
					</td>
					
				</tr>
				<tr>
					<td>
						<label>telefonszám:</label>
					</td>
					<td>
						<input  type='text' name='telefonszamTB' maxlength='20' size='20' value='<?php 
							if(isset($_POST['telefonszamTB']))
								print $_POST['telefonszamTB'];
						?>'>
					</td>
				</tr>
				<tr>
					<td>
						<label>aktiv:</label>
					</td>
					<td>
						<select name='aktivCB'>
							<option value="aktív" <?php if($_POST['aktivCB']=='aktív'){print "selected='selected' ";}?>>aktív</option>
							<option value="passzív" <?php if($_POST['aktivCB']=='passzív'){print "selected='selected' ";}?>>passzív</option>
						</select>
					</td>
					
				</tr>
				<tr>
					<td>
						<label>egyenleg:</label>
					</td>
					<td>
						<input  type='text' name='egyenlegTB' maxlength='20' size='20' value='<?php 
							if(isset($_POST['egyenlegTB']))
								print $_POST['egyenlegTB'];
						?>'>
					</td>
				</tr>
			</table>
		</form>
		
	</body>
</html>

